{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6431f4f5",
   "metadata": {},
   "source": [
    "### 填空题1"
   ]
  },
  {
   "cell_type": "raw",
   "id": "a4c0d9d8",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　一个包含有2019个结点的无向连通图，最少包含多少条边？\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "344f7b87",
   "metadata": {},
   "source": [
    "### 填空题2"
   ]
  },
  {
   "cell_type": "raw",
   "id": "898a8517",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　将LANQIAO中的字母重新排列，可以得到不同的单词，如LANQIAO、AAILNOQ等，注意这7个字母都要被用上，单词不一定有具体的英文意义。\n",
    "　　请问，总共能排列如多少个不同的单词。\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af67ea93",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "from math import perm\n",
    "\n",
    "print(perm(7, 7) // 2 )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e05d5f46",
   "metadata": {},
   "source": [
    "### 填空题3"
   ]
  },
  {
   "cell_type": "raw",
   "id": "fc1300ea",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　在计算机存储中，12.5MB是多少字节？\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c5a504c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "kb = 1024\n",
    "mb = 1024 * kb\n",
    "print(12.5 * mb)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f964151a",
   "metadata": {},
   "source": [
    "### 填空题4"
   ]
  },
  {
   "cell_type": "raw",
   "id": "790f517b",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　由1对括号，可以组成一种合法括号序列：()。\n",
    "　　由2对括号，可以组成两种合法括号序列：()()、(())。\n",
    "　　由4对括号组成的合法括号序列一共有多少种？\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3fae653b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "chars = list()\n",
    "\n",
    "chars.extend(['(' for _ in range(4)])\n",
    "\n",
    "chars.extend([')' for _ in range(4)])\n",
    "\n",
    "from itertools import product\n",
    "\n",
    "results = list(product(chars, repeat=8))\n",
    "\n",
    "\n",
    "num = 0\n",
    "for result in results:\n",
    "    if result == result[::-1]:\n",
    "        num = num + 1 \n",
    "\n",
    "print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d12b67eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "num = 0 \n",
    "for i in range(10000000, 1000000000):\n",
    "    string = str(i)\n",
    "    \n",
    "    if string.count('1') == 4 and string.count('2') == 4:\n",
    "        if string == string[::-1]:\n",
    "            num = num + 1\n",
    "            \n",
    "print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d520c7c4",
   "metadata": {},
   "source": [
    "### 编程题1 凯撒密码加密"
   ]
  },
  {
   "cell_type": "raw",
   "id": "b17cc7c9",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定一个单词，请使用凯撒密码将这个单词加密。\n",
    "　　凯撒密码是一种替换加密的技术，单词中的所有字母都在字母表上向后偏移3位后被替换成密文。即a变为d，b变为e，…，w变为z，x变为a，y变为b，z变为c。\n",
    "　　例如，lanqiao会变成odqtldr。\n",
    "输入格式\n",
    "　　输入一行，包含一个单词，单词中只包含小写英文字母。\n",
    "输出格式\n",
    "　　输出一行，表示加密后的密文。\n",
    "样例输入\n",
    "lanqiao\n",
    "样例输出\n",
    "odqtldr\n",
    "评测用例规模与约定\n",
    "　　对于所有评测用例，单词中的字母个数不超过100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b25cd06",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "string = list(input())\n",
    "\n",
    "for i in range(len(string)):\n",
    "    \n",
    "    char_ord = ord(string[i]) + 3\n",
    "        \n",
    "    string[i] = chr(char_ord if char_ord <= 122 else char_ord - 26)\n",
    "\n",
    "print(\"\".join(string))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8241d03",
   "metadata": {},
   "source": [
    "### 编程题2 反倍数"
   ]
  },
  {
   "cell_type": "raw",
   "id": "bdb56f0c",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定三个整数 a, b, c，如果一个整数既不是 a 的整数倍也不是 b 的整数倍还不是 c 的整数倍，则这个数称为反倍数。\n",
    "　　请问在 1 至 n 中有多少个反倍数。\n",
    "输入格式\n",
    "　　输入的第一行包含一个整数 n。\n",
    "　　第二行包含三个整数 a, b, c，相邻两个数之间用一个空格分隔。\n",
    "输出格式\n",
    "　　输出一行包含一个整数，表示答案。\n",
    "样例输入\n",
    "30\n",
    "2 3 6\n",
    "样例输出\n",
    "10\n",
    "样例说明\n",
    "　　以下这些数满足要求：1, 5, 7, 11, 13, 17, 19, 23, 25, 29。\n",
    "评测用例规模与约定\n",
    "　　对于 40% 的评测用例，1 <= n <= 10000。\n",
    "　　对于 80% 的评测用例，1 <= n <= 100000。\n",
    "　　对于所有评测用例，1 <= n <= 1000000，1 <= a <= n，1 <= b <= n，1 <= c <= n。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e915b12",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "\n",
    "a, b, c = map(int, input().split())\n",
    "\n",
    "nums = list()\n",
    "\n",
    "for i in range(1, n+1):\n",
    "    \n",
    "    if i % a != 0 and i % b != 0 and i % c != 0:\n",
    "        nums.append(i)\n",
    "        \n",
    "print(len(nums))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c665627",
   "metadata": {},
   "source": [
    "### 编程题3 摆动序列"
   ]
  },
  {
   "cell_type": "raw",
   "id": "57737d6d",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　如果一个序列的奇数项都比前一项大，偶数项都比前一项小，则称为一个摆动序列。即 a[2i]<a[2i-1], a[2i+1]>a[2i]。\n",
    "　　小明想知道，长度为 m，每个数都是 1 到 n 之间的正整数的摆动序列一共有多少个。\n",
    "输入格式\n",
    "　　输入一行包含两个整数 m，n。\n",
    "输出格式\n",
    "　　输出一个整数，表示答案。答案可能很大，请输出答案除以10000的余数。\n",
    "样例输入\n",
    "3 4\n",
    "样例输出\n",
    "14\n",
    "样例说明\n",
    "　　以下是符合要求的摆动序列：\n",
    "　　2 1 2\n",
    "　　2 1 3\n",
    "　　2 1 4\n",
    "　　3 1 2\n",
    "　　3 1 3\n",
    "　　3 1 4\n",
    "　　3 2 3\n",
    "　　3 2 4\n",
    "　　4 1 2\n",
    "　　4 1 3\n",
    "　　4 1 4\n",
    "　　4 2 3\n",
    "　　4 2 4\n",
    "　　4 3 4\n",
    "评测用例规模与约定\n",
    "　　对于 20% 的评测用例，1 <= n, m <= 5；\n",
    "　　对于 50% 的评测用例，1 <= n, m <= 10；\n",
    "　　对于 80% 的评测用例，1 <= n, m <= 100；\n",
    "　　对于所有评测用例，1 <= n, m <= 1000。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1eb06567",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "m, n = map(int, input().split())\n",
    "\n",
    "num = [i for i in range(1, n+1)]\n",
    "\n",
    "from itertools import product\n",
    "\n",
    "nums = list(product(num, repeat=3))\n",
    "\n",
    "\n",
    "def judge(value):\n",
    "    \n",
    "    for i in range(2, len(value), 2):\n",
    "        \n",
    "        if value[i] <= value[i-1]:\n",
    "            \n",
    "            return False\n",
    "        \n",
    "        \n",
    "    for i in range(1, len(value), 2):\n",
    "        \n",
    "        if value[i] >= value[i-1]:\n",
    "            \n",
    "            return False\n",
    "        \n",
    "    return True\n",
    "    \n",
    "for value in nums:\n",
    "    \n",
    "    if judge(value):\n",
    "        \n",
    "        print(value)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "332f2a5c",
   "metadata": {},
   "source": [
    "### 编程题4 螺旋矩阵"
   ]
  },
  {
   "cell_type": "raw",
   "id": "5a81d28c",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　对于一个 n 行 m 列的表格，我们可以使用螺旋的方式给表格依次填上正整数，我们称填好的表格为一个螺旋矩阵。\n",
    "　　例如，一个 4 行 5 列的螺旋矩阵如下：\n",
    "　　1  2  3  4  5\n",
    "　　14 15 16 17 6\n",
    "　　13 20 19 18 7\n",
    "　　12 11 10 9  8\n",
    "输入格式\n",
    "　　输入的第一行包含两个整数 n, m，分别表示螺旋矩阵的行数和列数。\n",
    "　　第二行包含两个整数 r, c，表示要求的行号和列号。\n",
    "输出格式\n",
    "　　输出一个整数，表示螺旋矩阵中第 r 行第 c 列的元素的值。\n",
    "样例输入\n",
    "4 5\n",
    "2 2\n",
    "样例输出\n",
    "15\n",
    "评测用例规模与约定\n",
    "　　对于 30% 的评测用例，2 <= n, m <= 20。\n",
    "　　对于 70% 的评测用例，2 <= n, m <= 100。\n",
    "　　对于所有评测用例，2 <= n, m <= 1000，1 <= r <= n，1 <= c <= m。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "18544b82",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4 5\n",
      "2 2\n",
      "[[1, 2, 3, 4, 5], [14, 15, 16, 17, 6], [13, 20, 19, 18, 7], [12, 11, 10, 9, 8]]\n"
     ]
    }
   ],
   "source": [
    "n, m = map(int, input().split())\n",
    "\n",
    "r, c = map(int, input().split())\n",
    "\n",
    "nums = [[0 for _ in range(m)] for _ in range(n)]\n",
    "_nums = [[0 for _ in range(m)] for _ in range(n)]\n",
    "\n",
    "x, y = 0, 0\n",
    "\n",
    "i = 1\n",
    "while i < n * m:\n",
    "    while y < m and _nums[x][y] == 0:\n",
    "        nums[x][y] = i\n",
    "        _nums[x][y] = 1\n",
    "        i = i + 1\n",
    "        y = y + 1\n",
    "        \n",
    "    y -= 1\n",
    "    x += 1\n",
    "    \n",
    "    while x < n and _nums[x][y] == 0:\n",
    "        nums[x][y] = i\n",
    "        _nums[x][y] = 1\n",
    "        i = i + 1\n",
    "        x = x + 1\n",
    "        \n",
    "    x -= 1\n",
    "    y -= 1\n",
    "    \n",
    "    while y >= 0 and _nums[x][y] == 0:\n",
    "        nums[x][y] = i\n",
    "        _nums[x][y] = 1\n",
    "        i = i + 1\n",
    "        y = y - 1\n",
    "        \n",
    "    x -= 1\n",
    "    y += 1\n",
    "    \n",
    "    while x >= 0 and _nums[x][y] == 0:\n",
    "        nums[x][y] = i\n",
    "        _nums[x][y] = 1\n",
    "        i = i + 1\n",
    "        x = x - 1\n",
    "        \n",
    "    x += 1\n",
    "    y += 1\n",
    "    \n",
    "\n",
    "print(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26f42875",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "lanqiaobei",
   "language": "python",
   "name": "lanqiaobei"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
